deserializeFromToml

fun <T : Any> deserializeFromToml(config: T, toml: TomlElement, errorBuilder: MutableList<String>, flags: Byte = 1): ValidationResult<ConfigContext<T>>

Deserializes a config class from a TomlElement

Custom deserializer, powered by TomlKt. Deserialization focuses on validation and building a useful error message. Deserialization happens in two ways

  1. EntrySerializer elements are deserialized with their custom deserializeEntry method

  2. "Raw" properties and fields are deserialized with the TomlKt by-class-type deserialization.

Configs are deserialized "in place". That is to say, the deserializer iterates over the relevant fields and properties of a pre-instantiated "default" config class. Each relevant field/property is filled in with the results of deserializing from the TomlElement at the matching TomlTable key. If for some reason there is a critical error, the initial config passed in, with whatever deserialization was successfully completed, will be returned as a fallback.

Should be called as a matched pair to serializeToToml. Ex: if ignoreNonSync is false on one end, it needs to be false on the other.

Return

Returns a ValidationResult of ConfigContext and applicable error, containing the config and any flag information

Author

fzzyhmstrs

Since

0.2.0

Parameters

T

the config type. Can be any Non-Null type.

config

the config pre-deserialization

toml

the TomlElement to deserialize from. Needs to be a TomlTable

errorBuilder

a mutableList of strings the original caller of deserialization can use to print a detailed error log

ignoreNonSync

default true. If false, elements with the NonSync annotation will be skipped. Use true to deserialize the entire config (ex: loading from file), use false for syncing (ex: initial sync server -> client)